import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
//引入测试数据
import { loginUsers, listCourse, listQuery,queryterInfo } from './data/user'
import { queryStudentMessage, QueryStudentUp, queryMoney, queryMoneySel} from './data/Query'
import { TeachermanageFy, TeachermanageSel, TeachermanageUp, TeachermanageDel, TeachermanageQx} from './data/manage_teacher'
import { queryEnterFy, queryEnterUp} from './data/manage_queryEnter'


import {noticeList,noticemanageSelid,noticemanageAdd} from './data/notice'
import {coursemanageDel, coursemanageSel2,coursemanageAdd,coursemanageUp,courseList,coursemanageSel} from './data/course'


import {listThesis, ThesisSel, ThesisUp } from './data/thesis'
import {listEducation, educationDel, educationAdd} from './data/education'

let _listCourse = listCourse
let _loginUsers = loginUsers
export default {

  mockTest() {
    let mock = new MockAdapter(axios) ;
    mock.onPost('/api/student/listCourse').reply(200,{status:200, message:'', resData: _listCourse}) ;

    //模拟学生登陆
    mock.onPost('/api/admin/login').reply(200,{status:200, message:'sdsd1', resData: _loginUsers});


    mock.onPost('/api/admin/logout').reply(200,{status:200, message:'scg1', resData:null});
    mock.onPost('/api/admin/queryterInfo').reply(200,{status:200, message:'222', resData:null});

        /*
        some() 方法用于检测数组中的元素是否满足指定条件（函数提供）。
        some() 方法会依次执行数组的每个元素：
        如果有一个元素满足条件，则表达式返回true , 剩余的元素不会再执行检测。
        如果没有满足条件的元素，则返回false。
        */
        /*
          JSON对象有两个方法：stringify()和parse()。在最简单的情况下，
          这两个方法分别用于把JavaScript对象序列化为JSON字符串和把JSON字符串解析为原生JavaScript。
        */

    //      let {user, password, rememberMe } = JSON.parse(config.data)
    //      return new Promise((resolve, reject) => { //异步操作，成功resolve继续执行
    //        let resultData = null ;
    //        setTimeout(() => {// 短暂延迟后
    //         let hasUser = loginUsers.some(u => {
    //           if (u.user === user && u.password === password) {
    //             resultData = JSON.parse(JSON.stringify(u));
    //             resultData.password = '';
    //             resultData.rememberMe = rememberMe;
    //             return true ;
    //           }
    //         })
    //         if (hasUser){/* 异步操作成功 */
    //           console.log("resultData:" + resultData);
    //           resolve([200,{status:200,message:'登陆成功',resultData}]);
    //         } else {
    //           reject(500,{status:505,message:'账号或密码错误'});
    //         }
    //       },200)
    //       });
    //
    //     // promise.then(function(value) {
    //     //  // success
    //     // }, function(value) {
    //     //  // failure
    //     // });
    // });
    /**
     * 审核
     */
  mock.onPost('/api/admin/queryStudentFy').reply(200,{status:200, message:'', resData: listQuery}) ;
  mock.onPost('/api/admin/queryStudentMessage').reply(200,{status:200, message:'', resData: queryStudentMessage}) ;
    mock.onPost('/api/admin/QueryStudentUp').reply(200,{status:200, message:'',resData: QueryStudentUp}) ;
      mock.onPost('/api/admin/queryMoney').reply(200,{status:200, message:'',resData: queryMoney}) ;
        mock.onPost('/api/admin/queryMoney').reply(200,{status:200, message:'',resData: queryMoneySel}) ;


  mock.onPost('/api/admin/queryEnterFy').reply(200,{status:200, message:'',resData: queryEnterFy}) ;
  mock.onPost('/api/admin/queryEnterUp').reply(200,{status:200, message:'',resData: queryEnterUp}) ;
        /**
         * 审教师管理
         */
        mock.onPost('/api/admin/TeachermanageFy').reply(200,{status:200, message:'',resData: TeachermanageFy}) ;
        mock.onPost('/api/admin/TeachermanageSel').reply(200,{status:200, message:'',resData: TeachermanageSel}) ;
        mock.onPost('/api/admin/TeachermanageUp').reply(200,{status:200, message:'',resData: TeachermanageUp}) ;
        mock.onPost('/api/admin/TeachermanageDel').reply(200,{status:200, message:'',resData: TeachermanageDel}) ;
        mock.onPost('/api/admin/TeachermanageQx').reply(200,{status:200, message:'',resData: TeachermanageQx}) ;

        /**
         * 学生论文管理
         */
        mock.onPost('/api/admin/papermanageFy').reply(200,{status:200, message:'', resData: listThesis}) ;
            mock.onPost('/api/admin/papermanageSel').reply(200,{status:200, message:'', resData: ThesisSel}) ;
            mock.onPost('/api/admin/papermanageUp').reply(200,{status:200, message:'', resData: ThesisUp}) ;

        /**
         * 教学计划管理
         */
            mock.onPost('/api/admin/educationFy').reply(200,{status:200, message:'', resData: listEducation}) ;
            mock.onPost('/api/admin/educationDel').reply(200,{status:200, message:'', resData: educationDel});
            mock.onPost('/api/admin/educationAdd').reply(200,{status:200, message:'', resData: educationAdd});

            //课程管理
    mock.onPost('/api/admin/coursemanageFy').reply(200,{status:200, message:'', resData: courseList}) ;
    mock.onPost('/api/admin/coursemanageSel').reply(config => {
      console.log("config" + config.data);
       let {id} = JSON.parse(config.data)
      return new Promise((resolve,reject) => {
        setTimeout(() => {
          console.log("id" + id + "config:" + config.data);
          if (config.data = 1) {
            resolve([200,{status:200, message:'', resData: coursemanageSel}]) ;
          } else if (config.data = 2) {
            resolve([200,{status:200, message:'', resData: coursemanageSel2}])
          } else {
             reject([500,{}])
          }
        },200)
    })
  });
    mock.onPost('/api/admin/coursemanageDel').reply(200,{status:200, message:'', resData: coursemanageDel}) ;
    mock.onPost('/api/admin/coursemanageUp').reply(200,{status:200, message:'', resData: coursemanageUp}) ;
    mock.onPost('/api/admin/coursemanageAdd').reply(200,{status:200, message:'', resData: coursemanageAdd}) ;

    //公告管理
    mock.onPost('/api/admin/noticemanageFy').reply(200,{status:200, message:'', resData: noticeList}) ;
    mock.onPost('/api/admin/noticemanageSel').reply(200,{status:200, message:'', resData: noticemanageSelid}) ;
    mock.onPost('/api/admin/noticemanageAdd').reply(200,{status:200, message:'', resData: noticemanageAdd}) ;
  }
}
